package cn.cjxy.javaweb.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * servlet创建
 *  继承HttpServlet
 *  重写service方法
 * @author huangjie
 * @date 2025/9/29
 */
public class MyServlet extends HttpServlet {
    /**
     *
     * @param req  对请求数据进行封装
     * @param resp 对响应数据进行封装
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            //向网页写入内容
        //设置响应格式
        resp.setContentType("text/html;charset=utf-8");

        //得到写对象
        PrintWriter writer = resp.getWriter();
        writer.println("<h1>hello tomcat</h1>");
    }
}
